<?php $this->load->view('layout/header_data_form');?>

<script type="text/javascript">
		var checkDisplay = function(check, form) { //check ID, form ID
			form = document.getElementById(form), check = document.getElementById(check);
			check.onclick = function(){
				form.style.display = (this.checked) ? "block" : "none";
				form.reset();
			};
			check.onclick();
		};
</script>

<script type="text/javascript">
function showhide(divid, state){
document.getElementById(divid).style.display=state
}
</script>


<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><h1>Existing Coverage</h1></td>
    <td align="right"><img src="<?php echo img_link("small-logo.gif"); ?>" width="147" height="38" /></td>
  </tr>
</table>
<div id="wrap">
  <p>1) Type: 
    
    <?php 
    foreach($endowments as $k => $v){
    	echo "Endowment".$k;
    }
    ?>
    , ...<br />
    2)  Type: 
  WL
  , ...<br />
  3) Type: Term, ...</p>

  <form id="form1" name="form1" method="post" action="<?php echo base_url().'existing_coverage/index/'.$param;?>">

<table border="0" cellpadding="7" cellspacing="0">
	<tr>
    	<td align="right" valign="top">
            <select name="select" class="field" id="type" onchange="location.href='<?php echo base_url().'existing_coverage/index/';?>'+this.value">
                 <option value="0" selected="selected">Choose Type</option>
                 <option <?php echo ($param == "Endowment" ? 'selected="selected"' : '');?> value="Endowment">Endowment</option>
                 <option <?php echo ($param == "Term" ? 'selected="selected"' : '');?> value="Term">Term</option>
                 <option <?php echo ($param == "ILP" ? 'selected="selected"' : '');?> value="ILP">ILP</option>
                 <option <?php echo ($param == "WL" ? 'selected="selected"' : '');?> value="WL">WL</option>
                 <option <?php echo ($param == "HS" ? 'selected="selected"' : '');?> value="HS">H & S</option>
            </select>        </td>
        
           
        <td align="left" valign="top">
        <?php if ($param == 'Endowment'):?> 
        	<div id="text1" style="">
            	<input name="textfield5" type="text" class="field" id="textfield5" size="20" value="<?php echo ($row ? $row["policy_incepted"] : "Policy Incepted")?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
                <input name="textfield" type="text" class="field" id="textfield" size="20" value="<?php echo ($row ? $row["policy_term"] : "Policy Term")?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
                <input name="textfield2a" type="text" class="field" id="textfield2a" size="23" value="<?php echo ($row ? $row["sum_assured_death"] : "Sum Assured for Death")?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
                <input name="textfield2b" type="text" class="field" id="textfield2b" size="25" value="<?php echo ($row ? $row["sum_assured_disability"] : "Sum Assured for Disability")?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
				<input name="textfield2c" type="text" class="field" id="textfield2c" size="30" value="<?php echo ($row ? $row["sum_assured_critical_illness"] : "Sum Assured for Critical Illness")?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
				<input name="textfield3a" type="text" class="field" id="textfield3a" size="20" value="<?php echo ($row ? $row["maturity_year"] : "Maturity Year")?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"/>
				<input name="textfield3b" type="text" class="field" id="textfield3b" size="20" value="<?php echo ($row ? $row["maturity_value"] : "Maturity Value")?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"/>
			</div>
		<?php endif;?>
		
		<?php if ($param == 'Term' || $param == 'ILP'):?> 
            <div id="text2" style="">
            	<input name="textfield5" type="text" class="field" id="textfield5" size="20" value="<?php echo($row ? $row["policy_incepted"]  : "Policy Incepted");?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
                <input name="textfield" type="text" class="field" id="textfield" size="20" value="<?php echo($row ? $row["policy_term"]  : "Policy Term");?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
                <input name="textfield22a" type="text" class="field" id="textfield22a" size="23" value="<?php echo($row ? $row["sum_assured_death"]  : "Sum Assured for Death");?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
                <input name="textfield22b" type="text" class="field" id="textfield22b" size="25" value="<?php echo($row ? $row["sum_assured_disability"]  : "Sum Assured for Disability");?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
				<input name="textfield22c" type="text" class="field" id="textfield22c" size="30" value="<?php echo($row ? $row["sum_assured_critical_illness"]  : "Sum Assured for Critical Illness");?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
			</div> 
		<?php endif;?>	 
		
		<?php if($param == 'WL'):?>
			 <div id="text2" style="">
            	<input name="textfield5" type="text" class="field" id="textfield5" size="20" value="<?php echo($row ? $row["policy_incepted"]  : "Policy Incepted");?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
                <input name="textfield" type="text" class="field" id="textfield" size="20" value="<?php echo($row ? $row["policy_term"]  : "Policy Term");?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
                <input name="textfield22a" type="text" class="field" id="textfield22a" size="23" value="<?php echo($row ? $row["sum_assured_death"]  : "Sum Assured for Death");?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
                <input name="textfield22b" type="text" class="field" id="textfield22b" size="25" value="<?php echo($row ? $row["sum_assured_disability"]  : "Sum Assured for Disability");?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
				<input name="textfield22c" type="text" class="field" id="textfield22c" size="30" value="<?php echo($row ? $row["sum_assured_critical_illness"]  : "Sum Assured for Critical Illness");?>" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
			</div> 
		<?php endif;?>
            </td>
        <td>
           
           <?php if ($param == 'Term'):?>
            <div id="t2" style="">
            	<label>
                	<input type="checkbox" <?php echo ($row && isset($row["decreasing"]) && $row["decreasing"]==1 ? "checked='checked'" : "");?> name="c1" id="Decreasing"/> Decreasing</label>
            </div>
            <?php endif;?>
			
			<?php if($param == 'WL'):?>
             <div id="t4" style="display:block;">
             	<label>
                    <?php
                        $step_up_booster = "";
                        $step_up_booster = ($row && isset($row["step_up_booster"]) && $row["step_up_booster"] ==1 ? "checked='checked'" : "");
                    ?>
                	<input type="checkbox" <?php echo $step_up_booster;?> name="step_booster" id="booster" />Step Up Booster</label>
                <div id="t44"><br />
                	<label>
                    	Year Start: <input name="year_start" type="text" id="year3a" size="10" value="<?php echo ($row ? $row["year_start"] : "");?>" class="field" /> 
                    </label><br />
					<label>
                    	Year End: <input name="year_end" type="text" id="percent3b" size="10" value="<?php echo ($row ? $row["year_end"] : "");?>" class="field" /> 
                    </label><br />
					<input name="addictional_sum_assured_death" value="<?php echo ($row && isset($row["addictional_sum_assured_death"]) ? $row["addictional_sum_assured_death"] : "Additional Sum Assured for Death");?>" type="text" class="field" id="textfield222a" size="33" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  /><br />
					<input name="addictional_sum_assured_disability" value="<?php echo ($row && isset($row["addictional_sum_assured_disability"]) ? $row["addictional_sum_assured_disability"] : "Additional Sum Assured for Disability");?>" type="text" class="field" id="textfield222b" size="35" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  /><br />
					<input name="addictional_sum_assured_critical" value="<?php echo ($row && isset($row["addictional_sum_assured_critical"]) ? $row["addictional_sum_assured_critical"] : "Additional Sum Assured for Critical Illness");?>" type="text" class="field" id="textfield222c" size="40" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  /><br /><br />
                </div>
            </div>
            <?php endif;?>
            
            <?php if($param == 'WL'):?>
			 <div id="t3" style="">
            	<label>
                	<input type="checkbox" <?php echo($row && isset($row["consider_cash_value_retirement"]) && $row["consider_cash_value_retirement"] == 1 ? "checked='checked'" : "");?> name="consider_cash_value_retirement" id="retirement1" onclick="showMe("t333", this)" />Consider C/V for Retirement</label>
             	<div id="t333"><br />
                	<label>
                    	Retirement Age: <input name="retirement_age" value="<?php echo ($row ? $row["retirement_age"] : "");?>" type="text" id="percent2" size="4" class="field" />  
                    </label><br />
                    <label>
                    	C.V At Retirement: <input name="cva_retirement" value="<?php echo ($row ? $row["cva_retirement"] : "");?>" type="text" id="C.V At Retirement" size="20" class="field" /> 
                    </label>
                 </div>
                 <br />
             </div>
             <?php endif;?>
			
			<?php if($param == 'HS'):?>
            <div id="t5" style="">
            	<label>
                	<input name="percent4" type="text" id="percent4" size="30" value="Company" class="field" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"  />
                </label><br />
            </div>   
            <?php endif;?>     
			
			<?php if($param == 'ILP'):?>
			<div id="t6" style="">
            	<label>
                	<input type="checkbox" <?php echo($row && isset($row["consider_cash_value_retirement"]) && $row["consider_cash_value_retirement"] == 1 ? "checked='checked'" : "");?> name="consider_cash_value_retirement" id="retirement2" onclick="showMe("t334", this)" />Consider C/V for Retirement</label>
             	<div id="t334"><br />
                	<label>
                    	Retirement Age: <input name="retirement_age" value="<?php echo ($row ? $row["retirement_age"] : "");?>" type="text" id="percent2" size="4" class="field" />  
                    </label><br />
                    <label>
                    	C.V At Retirement: <input name="cva_retirement" value="<?php echo ($row ? $row["cva_retirement"] : "");?>" type="text" id="C.V At Retirement" size="20" class="field" /> 
                    </label><br />
					<label>
                    	Expected Annual Return: <input name="expected_annual_return" value="<?php echo ($row ? $row["expected_annual_return"] : "");?>" type="text" id="percent2z" size="4" class="field" />  
                    </label>
                 </div>
                 <br />
             </div>
			<?php endif;?>
			
			</td>
      </tr>
</table>        
<br />

[Add]

<br />
<br />
<input class="large button green" type="submit" value="Calculate"/>

<div id="graph" style="">
<br />
<br />
 <?php if(!$row || !$param):?>
 <?php else:?>
 <?php $this->load->view('existing_coverage/chart_existing_coverage_'.strtolower($param));
 	//$this->load->view('existing_coverage/chart_existing_coverage_endowment_jqflot');
 ?>
 <?php endif;?>
 <input type="hidden" value="0" id="submit" name="submit" />
 </form>
 <form id="form2" name="form2" method="post" action="<?php echo base_url().'existing_coverage/index/'.$param;?>">
 	<input type="hidden" value="1" id="submit" name="submit" />
            <table border="0" cellpadding="7" cellspacing="0">
              <tr>
                <td align="left"><strong>Explanation:</strong></td>
              </tr>
              <tr>
                <td align="left"><textarea name="textfield3" cols="60" rows="6" class="field" id="textfield3"><?php echo ($row && isset($row["explanation_".strtolower($param)]) ? $row["explanation_".strtolower($param)] : "")?></textarea></td>
              </tr>
              <tr>
                <td align="right"><input type="submit" class="large button red" value="Submit" /></td>
              </tr>
          </table>
</form>
<br />
</div>
<br />



<br />
  <a href="JavaScript:window.close();"><img src="images/cwindow.jpg" alt="Close Window" width="82" height="15" border="0" /></a>

<script type="text/javascript">
	checkDisplay("retirement1", "t333");
</script>

<script type="text/javascript">
	checkDisplay("retirement2", "t334");
</script>

<script type="text/javascript">
	checkDisplay("booster", "t44");
</script>

<script language="javascript"> 
	function ShowDiv(){
		//safeToggleFieldDisplay('one');
		//safeToggleFieldDisplay('two');
		//safeToggleFieldDisplay(document.getElementById('three'),'none');
		//safeToggleFieldDisplay(document.getElementById('four'),'none');
 
		var dropdown = document.getElementById("type");
		var index = dropdown.selectedIndex;
		var selectedDIV = dropdown.options[index].value;
		safeToggleFieldDisplay(selectedDIV);
	}
	
	function safeToggleFieldDisplay(field){
		try{
			 if(field == '0'){
				document.getElementById('text1').style.display = 'none';
				document.getElementById('text2').style.display = 'none';
				document.getElementById('t2').style.display = 'none';
				document.getElementById('t3').style.display = 'none';
				document.getElementById('t4').style.display = 'none';
				document.getElementById('t5').style.display = 'none';
				document.getElementById('t6').style.display = 'none';
			}
			else if(field == 'Endowment'){
				document.getElementById('text1').style.display = 'block';
				document.getElementById('text2').style.display = 'none';
				document.getElementById('t2').style.display = 'none';
				document.getElementById('t3').style.display = 'none';
				document.getElementById('t4').style.display = 'none';
				document.getElementById('t5').style.display = 'none';
				document.getElementById('t6').style.display = 'none';
			}
			else if(field == 'Term'){
				document.getElementById('text1').style.display = 'none';
				document.getElementById('text2').style.display = 'block';
				document.getElementById('t2').style.display = 'block';
				document.getElementById('t3').style.display = 'none';
				document.getElementById('t4').style.display = 'none';
				document.getElementById('t5').style.display = 'none';
				document.getElementById('t6').style.display = 'none';
			} 
			else if(field == 'ILP'){
				document.getElementById('text1').style.display = 'none';
				document.getElementById('text2').style.display = 'block';
				document.getElementById('t2').style.display = 'none';
				document.getElementById('t3').style.display = 'none';
				document.getElementById('t4').style.display = 'none';
				document.getElementById('t5').style.display = 'none';
				document.getElementById('t6').style.display = 'block';
			} 
			else if(field == 'WL'){
				document.getElementById('text1').style.display = 'none';
				document.getElementById('text2').style.display = 'block';
				document.getElementById('t2').style.display = 'none';
				document.getElementById('t3').style.display = 'block';
				document.getElementById('t4').style.display = 'block';
				document.getElementById('t5').style.display = 'none';
				document.getElementById('t6').style.display = 'none';
			} 
			else if(field == 'HS'){
				document.getElementById('text1').style.display = 'none';
				document.getElementById('text2').style.display = 'none';
				document.getElementById('t2').style.display = 'none';
				document.getElementById('t3').style.display = 'none';
				document.getElementById('t4').style.display = 'none';
				document.getElementById('t5').style.display = 'block';
				document.getElementById('t6').style.display = 'none';
			} 
		}
		catch(exception){
			//no handling - just preventing page explosions
		}
	}
 
	//ShowDiv();
</script> 

  
</div>

<?php $this->load->view('layout/footer_data_form');?>